﻿CREATE PROCEDURE [dbo].[proc_Assets_BF_Getlist]
	(
		@CompanyId int,
		@CategoryId int,
		@NameId int,
		@StartIndex int,
		@EndIndex int
	)
AS
	;WITH list as (Select ROW_NUMBER() OVER (ORDER BY a.StateId)AS Row,
	a.Id,
	a.GId,
	a.CategoryId,
	(Select Title From Assets_Categorys Where Id=a.CategoryId) As CategoryName,
	NameId,
	(Select Title From Assets_Names Where Id=a.NameId) As NameTitle,
	Description,
	CompanyId,
	(Select CompanyName From Company Where Id=a.CompanyId) As CompanyName,
	DepartmentId,
	(Select DName From Department Where Id=a.DepartmentId) As Department,
	UserName,
	EName,
	StateId,
	(Select Title From Assets_States Where Id=a.StateId) As StateName,
	Prices,
	DJUserName,
	DJDate,
	GGXH,
	GZDate,
	IsApplyBf,
	Memo,
	ApplyBFDate,
	ANumber
	From Assets a
	Where (@CompanyId=0 Or a.CompanyId=@CompanyId) and (@CategoryId=0 Or a.CategoryId=@CategoryId) and (@NameId=0 Or a.NameId=@NameId) and IsApplyBf=1 AND StateId<>3
	)
	Select *,(SELECT COUNT(1) FROM list) AS cid From list Where Row between @StartIndex and @EndIndex
	RETURN
